package mycompany.model.message;

import mycompany.model.UserBaseModel;

/**
 * Represents message model
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 */
public class PrivateMessageModel <U extends UserBaseModel> extends MessageBaseModel {
    
    private boolean isRead = false;
    private boolean isRemoved = false;
    
    /**
     * Constructs an instance
     * @param id defines message id
     * @param text defines message text
     * @param userId defines user id
     */
    public PrivateMessageModel(long id, String text, U user){
        super(id, text, user);
    }

    public boolean isRemoved() {
        return isRemoved;
    }

    public boolean markAsRemoved(U user) {
        boolean allowOperation = this.user.equals(user);
        if(allowOperation) {
            this.isRemoved = true;
            this.text = "";
        }
        return allowOperation;
    }
    
    public boolean isRead() {
        return isRead;
    }

    public void markAsRead(U user) {
        if(!this.user.equals(user)) this.isRead = true;
    }
}
